<template>
    <div class="login-account">
        <form class="styleSheet" action="#">
            <div class="row form-group">
                <div class="col-md-12 margin-top10">
                    <Input v-model="account" placeholder="手机号码">
                    <span slot="prepend"><Icon type="person"></Icon></span>
                    </Input>
                </div>
            </div>
            <div class="row form-group">
                <div class="col-md-12 margin-top10">
                    <Input v-model="password" type="password" placeholder="登录密码">
                    <span slot="prepend"><Icon type="locked"></Icon></span>
                    <Button slot="append" @click="forgetPwd">忘记密码?</Button>
                    </Input>
                </div>
            </div>
            <div class="row form-group">
                <div class="col-md-12 margin-top10">
                    <Checkbox v-model="remember">记住密码</Checkbox>
                </div>
            </div>
            <div class="row form-group">
                <div class="col-md-12">
                    <Button type="primary" long @click="loginAction">确认提交</Button>
                </div>
            </div>

        </form>
    </div>
</template>

<script>
    import getData from '@/api/getData'
    export default {
        data(){
            return {
                account: '',
                password: '',
                remember: true,
            }
        },
        methods: {
            // 登陸到指定的頁面
            loginAction: function () {
                var self = this;
                if(!this.account){
                    self.$Message.error('请输入用户名');
                    return false;
                }
                if(!this.password){
                    self.$Message.error('请输入密码');
                    return false;
                }
                var isRemember = 1;
                if(!this.remember){
                    isRemember = 0;
                }
                var paramObj = {
                    userName: this.account,
                    UserPwd: this.password,
//                    记住密码 0 不记住 1 记住
                    remember: isRemember
                };
                getData.post("Login", paramObj)
                    .then(function (response) {
                        if (response.data.code === 0) {
                            self.$Message.info(response.data.msg);
                            self.$router.push({name: 'homeIndex'});
                            // 添加标记，判断用户是否登录
                            window.localStorage.setItem("isLogin","true");
                        } else {
                            self.$Message.error(response.data.msg)
                        }
                    })
                    .catch(function (response) {
                        console.log(response);
                    });

            },
            // 忘记密码
            forgetPwd: function () {
                this.$emit('forget-pwd','forgetPwd')
            }
        },
    }
</script>

<style lang="scss">
    .login-account {
        .styleSheet {
            padding: 30px 40px;
        }
        .margin-top10 {
            margin-top: 10px;
        }
    }
</style>
